// JavaScript Document
$(function() {
    $(document).on("focus", "input,textarea,select", function(e) {
//        $(this).parent().parent().siblings().children().children().removeClass("green")
        $(":input").removeClass("green");
        $(this).addClass("green");
    });
	$(document).on("click",'.fhqx',function(e){
        var step = $(this).attr('step');
		$(".biaodan"+step).hide();
		$(".neirong"+step).show();
    })
	$(document).on("click", ".add1", function(e) {
		
		var num = $(this).attr("num");
		var step = $(this).attr('step');
		$(".biaodan"+step).show();
		$(".neirong"+step).hide();
		$.ajax({
			   
				url: "/Tea/Index/s2html",
				data: "num="+num+"&step="+step+"&user_id="+user_id,
				type:"post",
				dataType: "json",
				success:function(ret){
				
					$(".s"+step+"html").html(ret.info);
				}
			
		});
		
		
    });
	$(document).on("click",'.edit',function(e){
        var step = $(this).attr('step');
		var num = $(this).attr('num');
		$(".biaodan"+step).show();
		$(".neirong"+step).hide();
		if(num)
		{
			$.ajax({
			   
				url: "/Tea/Index/s2html",
				data: "num="+num+"&step="+step+"&user_id="+user_id,
				type:"post",
				dataType: "json",
				success:function(ret){
					$(".s"+step+"html").html(ret.info);
					//
				}
			
			});
		}
		else
		{
			$(".text"+step).hide();
			$(".post"+step).show();
		}
    });
    $(document).on("click", "#pereonal", function(e) {
		var step = $(this).attr('step');
		
		var ptc = $(this).attr('ptc');
		var num = $(this).attr('num');
		
		if(step==1)
		{
			var first_name = getValue("first_name");
			var last_name = getValue("last_name");
			if(first_name=='') return alert('Please fill in First Name！');
			if(last_name=='') return alert('Please fill in Last Name！');
			
			var email = checkemail($("input[name='email']").val());
			var address = $("#address").val();
			var mob = checkmobile($("input[name='mobile']").val());
			var str = "&first_name="+first_name+"&last_name="+last_name+"&email="+email+"&address="+address+"&mob="+mob;
		}
		if(step==2)
		{
			var objective = $("#objective").val();
			if(objective==''||objective=='Your expected job position or career goal etc. For example,Seeking the online English teacher position at XXX company') return alert('Please fill in OBJECTIVE！');
			
			var str = "&objective="+objective;
		}
		if(step==3)
		{
			
			var school = $(this).parent().parent().children().children('#school').val();
			if(school=='') return alert('Please fill in School！');
			var degree = $(this).parent().parent().children().children('#degree').val();
			if(degree=='') return alert('Please fill in Degree！');
			if(num)
			{
				var str = $("#form"+step+'-'+num).serialize();
				str = "&num="+num+"&"+str;
			}
			else
			{
				var str = $("#form"+step).serialize();
				str = "&"+str;
			}
			
			
		}
		if(step==4)
		{
			var company = $("#company").val();
            if (company == '')
                return alert('Please fill in Company Name！');
            var position = $("#position").val();
            if (position == '')
                return alert('Please fill in Position！');
            var month1 = $("input[name='month1']").val();
            if (month1 == '')
                return alert('Please fill in start month ！');
            var year1 = $("input[name='year11']").val();
            if (year1 == '')
                return alert('Please fill in start year ！');
            var month2 = $("input[name='month2']").val();
            if (month2 == '')
                return alert('Please fill in end month ！');
            var year2 = $("input[name='year22']").val();
            if (year2 == '')
                return alert('Please fill in start year ！');
            if (year1 > year2) {
                return alert("End time must be greater than start time!");
            } else if (year1 == year2) {
                if (month1 >= month2) {
                    return alert('End time must be greater than start time!');
                }
            }
			var description1 = $("#description1").val();
            if (description1 == '')
                return alert('Please fill in Description！');
			if(num)
			{
				var str = $("#form"+step+'-'+num).serialize();
				str = "&num="+num+"&"+str;
			}
			else
			{
				var str = $("#form"+step).serialize();
				str = "&"+str;
			}
			
			
			
		}
		if(step==5)
		{
			
			//var str = $("#form"+step).serialize();
			str = '';
			var i = 1;
			$("input[name=lang]").each(function(){
				str += '&lang'+i+'='+$(this).val();
				i ++ ;
			});
			i=1;
			$("input[name=level]").each(function(){
				str += '&level'+i+'='+$(this).val();
				i ++ ;
			});
			
		}
		if(step==6)
		{
			var assessment = $("#assessment").val();
			if(assessment==''||assessment=='Please tell us something about yourself, such as:characher、hobb') return alert('Please fill in ASSESSMENT！');
			
			var str = "&assessment="+assessment;
			
		}
		$.ajax({
			   
				url: "/Tea/Index/postResume",
				data: "step="+step+"&precentum="+ptc+str+"&user_id="+user_id,
				type:"post",
				dataType: "json",
				success:function(ret){
					if(ret.status==0)  return alert($ret.info);
					if(ret.status==1)
					{
						alert('success！');
						//$(".text"+step).show();
						//$(".post"+step).hide();
						//$(".con"+step).html();
						location.reload() ;
					}
				}
			
		});
       
        
    });
	$(document).on("click",'.sel',function(e){
       $(this).children(".lieb").slideToggle(200);
    });
	
	$(document).on("click", '.sell', function(e) {
        $(this).children(".llieb").slideToggle(200);
    });
    $(document).on("click", '.dellang', function(e) {
        $(this).parent().remove();
    });
    $(document).on("click", '.lieli', function(e) {
        var html = $(this).html();
        $(this).parent(".lieb").parent(".sel").children(".selinput").html(html);
        $(this).parent(".lieb").children("#year").val(html);
        $(this).parent(".llieb").parent(".sell").children(".sellinput").html(html);
        $(this).parent(".llieb").children("#year").val(html);
    });
	
	
	
	$(document).on("click",'.del',function(e){
        var step = $(this).attr('step');
		var num = $(this).attr('num');
		$.ajax({
			   
				url: "/Tea/Index/delResume",
				data: "step="+step+"&num="+num+"&user_id="+user_id,
				type:"post",
				dataType: "json",
				success:function(ret){
					if(ret.status==0)  return alert($ret.info);
					if(ret.status==1)
					{
						alert('success！');
						//$(".text"+step).show();
						//$(".post"+step).hide();
						//$(".con"+step).html();
						location.reload() ;
					}
				}
			
		});
		
    });
	$(document).on("click",'.add',function(e){
       
		var num = $(this).attr('anum');
		$(this).attr('anum',parseInt(num)+1);
		
		$.ajax({
			   
				url: "/Tea/Index/postLang",
				data: "anum="+num+"&user_id="+user_id,
				type:"post",
				dataType: "json",
				success:function(ret){
					$(".biaodan5").append(ret.info);
				}
			
		});
		
    });
	$(document).on("click",'.qx',function(e){
        var step = $(this).attr('step');
		var num = $(this).attr('num');
		if(num)
		{
			var step = $(this).attr('step');
			$(".biaodan"+step).hide();
			$(".neirong"+step).show();
			
		}
		else
		{
			$(".text"+step).show();
			$(".post"+step).hide();
		}
    })
	
	
	
	$(document).on("focus",'input',function(e){
		var v = $(this).attr('v');
        var val = $(this).val();
		if(val==v) $(this).val('');
    })
	$(document).on("blur",'input',function(e){
		var v = $(this).attr('v');
        var val = $(this).val();
		if(val=='') $(this).val(v);
    })
    $(document).on("focus",'#objective',function(e){
		var objective=$('#objective').val();
        if(objective=='Your expected job position or career goal etc. For example,Seeking the online English teacher position at XXX company'){
            $(this).html("");
        }
       
    })
    $(document).on("blur",'#objective',function(e){
        var objective=$('#objective').val();
        if(objective==''){
            $(this).html("Your expected job position or career goal etc. For example,Seeking the online English teacher position at XXX company");
        }
    })
    $(document).on("blur", "input,textarea,select", function(e) {
        var value = $(this).val();
        if (value == '') {
            $(this).siblings('div').show();
        }
        var name = $("input[name='name']").val();
        var email = $("input[name='email']").val();
        var address = $("input[name='address']").val();
        var mob = $("input[name='mobile']").val();
        if (name != '') {
            $("input[name='name']").siblings('div').hide();
        }
        if (mob != '') {
            var mobile = mob.match(/^1[3|4|5|8][0-9]\d{4,8}$/);
            if (mobile) {
                $("#tishi_mobile").hide();
            } else {
                $("#tishi_mobile").html("请填写有效的11位手机号码！")
                $("#tishi_mobile").show();
            }
        }else{
            $("#tishi_mobile").hide();
        }
        if (email != '') {
            var flag = email.match(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/);
            if(flag){
                $("#tishi_email").hide();
            }else{
                $("#tishi_email").html("请填写有效的邮箱地址！")
                $("#tishi_email").show();
            }
        }else{
            $("#tishi_email").hide();
        }
    });
})
//获取值 并处理值
function getValue(con)
{
	var v = $("#"+con).attr('v');
	var va =  $("#"+con).val();
	if(v==va||va=='')
	{
		return '';
	}
	else
	{
		return va;
	}
}
function checkmobile(mobile){
    if(mobile){
        if(mobile.match(/^1[3|4|5|8][0-9]\d{4,8}$/)){
            return mobile;
        }else{
            return false;
        }
    }else{
        return mobile;
    }
}
function checkemail(email){
    if(email){
        if(email.match(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)){
            return email;
        }else{
            return false;
        }
    }else{
        return email;
    }
}